package com.seednia.module.util.file.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.seednia.foundation.framework.service.AbstractService;
import com.seednia.module.util.file.dto.FileDto;
import com.seednia.module.util.file.service.IFileService;

/**
 * Template provider service
 * 
 * @author Young Suk Ahn
 *
 */
public class FileDefaultService extends AbstractService implements IFileService {
	
	private static final Log logger = LogFactory.getLog(FileDefaultService.class);
	
	@Override
	public void initialize() {

	}

	@Override
	public FileDto getFile(String name) {

		FileDto retval = new FileDto();
		retval.setName(name);
		
		int extensionStart =  retval.getName().lastIndexOf(".");
		if (extensionStart > 0) {
			String extension = retval.getName().substring(extensionStart+1);
			if (extension.equalsIgnoreCase("jpg") || extension.equalsIgnoreCase("jpeg")) {
				retval.setContentType("image/jpeg");
			} else if (retval.getName().endsWith("png")) {
				retval.setContentType("image/png");
			} else if (retval.getName().endsWith("gif")) {
				retval.setContentType("image/gif");
			} else if (retval.getName().endsWith("tiff")) {
				retval.setContentType("image/tiff");
			}
		}
		
		return retval;
	}

}
